package com.sghj.SysPermission.entity;

import com.baomidou.mybatisplus.annotation.*;
import com.sghj.config.core.domain.BaseEntity;
import com.sghj.utils.ValidateUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

import javax.validation.constraints.DecimalMin;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;
import java.util.Date;

/**
 * <p>
 * 
 * </p>
 *
 * @author xrx
 * @since 2022-02-26
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName("sys_role")
@ApiModel(value="SysRole对象", description="")
public class SysRole extends BaseEntity {

    @ApiModelProperty(value = "角色ID")
    @TableId(value = "SysRoleId", type = IdType.AUTO)
    private Integer SysRoleId;

    @ApiModelProperty(value = "角色名称")
    @TableField("SysRoleName")
    @Pattern(regexp = ValidateUtil.UNBLANK_PATTERN,message = "角色名称不规范")
    @Size(min = 2,max = 10,message = "角色名称长度为2-10个字符")
    private String SysRoleName;

    @ApiModelProperty(value = "权限字符")
    @Pattern(regexp = ValidateUtil.UNBLANK_PATTERN,message = "权限字符不规范")
    @Size(min = 2,max = 10,message = "权限字符长度为2-10个字符")
    private String roleKey;

    @ApiModelProperty(value = "数据范围")
    private Integer dataScope;

    @ApiModelProperty(value = "显示排序")
    @TableField("DisplayOrder")
    @DecimalMin(value = "0",message = "输入必须为大于0的数字")
    private Integer DisplayOrder;
    //
    //@TableField("menu_check_strictly")
    //private Integer menuCheckStrictly;
    //
    //@TableField("dept_check_strictly")
    //private Integer deptCheckStrictly;

    @TableField("status")
    private Integer status;

    @ApiModelProperty(value = "0可用 1删除")
    @TableField("is_delete")
    @TableLogic
    private Integer isDelete;

    @ApiModelProperty(value = "创建时间")
    @TableField(fill = FieldFill.INSERT)
    private Date createTime;

    @ApiModelProperty(value = "更新时间")
    @TableField(fill = FieldFill.INSERT_UPDATE)
    private Date updateTime;

    @ApiModelProperty(value = "备注")
    //@Pattern(regexp = ValidateUtil.UNBLANK_PATTERN,message = "备注格式有误")
    @Size(max = 200)
    @TableField("remark")
    private String remark;

    /**
     * 用户是否存在此角色标识 默认不存在
     */
    @TableField(exist = false)
    private boolean flag = false;

    /**
     * 菜单组
     */
    @TableField(exist = false)
    private String[] menuIds;

    /**
     * 部门组（数据权限）
     */
    @TableField(exist = false)
    private Integer[] deptIds;

    public boolean isAdmin() {
        return isAdmin(this.SysRoleId);
    }

    public static boolean isAdmin(Integer roleId) {
        return roleId != null && roleId==1;
    }

}
